﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace MotoGame.Core
{
    class KeyInput
    {
        #region Properties
        KeyboardState last;
        KeyboardState Last
        {
            get { if (last == null) Last = Keyboard.GetState(); return last; }
            set { last = value; }
        }

        IDictionary<Keys, Action> mapping;
        public IDictionary<Keys, Action> Mapping
        {
            get { return mapping; }
        }
        #endregion

        #region Constructors
        public KeyInput()
        {
            mapping = new Dictionary<Keys, Action>();
        }
        #endregion

        #region Operations
        public void Update(GameTime gameTime)
        {
            KeyboardState current = Keyboard.GetState();

            foreach(var entry in Mapping)
            {
                if(Last.IsKeyDown(entry.Key) && current.IsKeyDown(entry.Key))
                {
                    entry.Value();
                }
            }

            Last = current;
        }
        #endregion
    }
}
